package com.atguigu.order.web;

import com.alipay.api.AlipayApiException;
import com.atguigu.order.config.AlipayTemplate;
import com.atguigu.order.service.OrderService;
import com.atguigu.order.vo.PayVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
public class PayWebController {

  @Resource
  private AlipayTemplate alipayTemplate;

  @Resource
  private OrderService orderService;

  @ResponseBody
  @GetMapping(value = "/aliPayOrder", produces = "text/html")
  public String aliPayOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
    System.out.println("接收到订单信息orderSn：" + orderSn);
    PayVo payVo = orderService.getOrderPay(orderSn);
    String pay = alipayTemplate.pay(payVo);
    return pay;
  }


}
